package com.ruoyi.common.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonValue;
import com.ruoyi.common.annotation.EnumConverter;
import com.ruoyi.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.core.convert.converter.Converter;

/**
 * 业务用户类型
 * 工作人员，吸毒人员
 */
@Getter
@AllArgsConstructor
@JsonFormat(shape = JsonFormat.Shape.STRING)
public enum PlaceType {

    /**
     * 房屋
     */
    PLACE_NORMAL("place_normal"),
    /**
     * 易制毒
     */
    PLACE_YZD("place_yzd"),
    /**
     * 易滥用
     */
    PLACE_YLY("place_yly"),
    /**
     * 易制毒化学企业
     */
    PLACE_YZDHXQY("place_hxpqy");


    @EnumValue
    private final String userType;

    @JsonValue
    public String getPlaceType() {
        return userType;
    }

    @EnumConverter
    public static class InnerConverter implements Converter<String, PlaceType> {
        @Override
        public PlaceType convert(String source) {
            return getPlaceType(source);
        }

    }

    public static PlaceType getPlaceType(String str) {
        for (PlaceType value : values()) {
            if (StringUtils.contains(str, value.getPlaceType())) {
                return value;
            }
        }
        throw new RuntimeException("'PlaceType' not found By " + str);
    }

}
